package com.atguigu.gulimall.zzmycanal.config;

import com.alibaba.otter.canal.protocol.CanalEntry;

import java.util.List;

public class ShowObj {

     public static void showData(CanalEntry.RowData rowData) {
        List<CanalEntry.Column> c1 = rowData.getBeforeColumnsList();
        List<CanalEntry.Column> c2 = rowData.getAfterColumnsList();
        if (c1.size() > 0 && c2.size() > 0) { //表示update
            for (int i = 0; i < c1.size(); i++) {
                CanalEntry.Column cx = c1.get(i);
                CanalEntry.Column cy = c2.get(i);
                if (!cx.getValue().equals(cy.getValue())) {
                    System.out.print("更新数据....");
                    System.out.println(cx.getName() + ":" + cx.getValue() + "--->" + cy.getName() + ":" + cy.getValue());
                }
            }
        }
        if (c1.size() == 0 && c2.size() > 0) {//表示新增
            System.out.print("添加数据....");
            for (int i = 0; i < c2.size(); i++) {
                CanalEntry.Column cy = c2.get(i);
                if (i == c2.size()) {
                    System.out.println(cy.getName() + ":" + cy.getValue() + "   ");
                }
                System.out.print(cy.getName() + ":" + cy.getValue() + "   ");

            }

        }
    }
}
